def is_prime(num):
    if num <= 1:
        return False
    for i in range(2, num // 2 + 1):
        if num % i == 0:
            return False
    return True

def permutations(num):
    a = []
    for i in range (len(num)):
        for j in range (i + 1, len(num) + 1):
            if len(num[i: i + j]) > 0:
                a.append(int(num[i:j]))
    return a

def max_prime(arr):
    max = 0
    for i in arr:
        if is_prime(i) and i > max:
            max = i
    return max

num = input()
arr = permutations(num)
max = max_prime(arr)
print(max)
